package com.songshuai.sales.tool.controller;

import com.songshuai.webapi.baseapi.dto.pangu.request.phpsop.PhpSopReqDto;
import com.songshuai.sales.tool.service.PhpSopService;
import com.songshuai.webapi.baseapi.enumerations.ResultStatus;
import com.songshuai.webapi.baseapi.pojo.QueryRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api("php_sop")
@RestController
@RequestMapping("/api/php/sop/")
public class PhpSopController {

    @Autowired
    private PhpSopService phpSopService;

    @ApiOperation("分类列表")
    @GetMapping("typeList")
    public QueryRes queryPhpSopTypeList(@RequestParam("typeId") String typeId){
        try {
            return phpSopService.queryPhpSopTypeList(typeId);
        } catch (Exception e) {
            log.error("查询分类列表异常：{}", e);
            return new QueryRes(ResultStatus.ERROR_SEARCH_FAILED.getErrorCode(),e.getMessage());
        }
    }

    @ApiOperation("sop内容列表")
    @PostMapping("sopList")
    public QueryRes queryPhpSopList(@RequestBody PhpSopReqDto sopReqDto){
        try {
            return phpSopService.queryPhpSopList(sopReqDto);
        } catch (Exception e) {
            log.error("查询sop内容列表异常：{}", e);
            return new QueryRes(ResultStatus.ERROR_SEARCH_FAILED.getErrorCode(),e.getMessage());
        }
    }

    @ApiOperation("sop内容详情")
    @GetMapping("sopDetail")
    public QueryRes queryPhpSopDetail(@RequestParam("id") String id){
        try {
            return phpSopService.queryPhpSopDetail(id);
        } catch (Exception e) {
            log.error("查询sop内容详情异常：{}", e);
            return new QueryRes(ResultStatus.ERROR_SEARCH_FAILED.getErrorCode(),e.getMessage());
        }
    }

}
